﻿<Window x:Class="SuplexApp.MainDlg"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
        xmlns:local="clr-namespace:SuplexApp"
        xmlns:cc="clr-namespace:SuplexApp.Controls"
        xmlns:splx="clr-namespace:Suplex.Wpf;assembly=Suplex.Wpf"
        xmlns:splxApi="clr-namespace:Suplex.Forms.ObjectModel.Api;assembly=Suplex.Core"
        Closing="MainDlg_Closing"
        Height="800" Width="1000" Background="LightGray">
    <Window.Resources>
        <local:SaveImageConverter x:Key="saveImageConverter" />
        <local:DialogTitleConverter x:Key="dialogTitleConverter" />
        <DataTemplate x:Key="RecentFile">
            <TextBlock Text="{Binding}"/>
        </DataTemplate>
        <DataTemplate x:Key="RecentConnection">
            <TextBlock Text="{Binding}"/>
        </DataTemplate>
    </Window.Resources>

    <Window.Title>
        <MultiBinding Converter="{StaticResource dialogTitleConverter}" ConverterParameter="Suplex">
            <Binding Path="ConnectionPath"/>
            <!--<Binding Path="IsConnected"/>
            <Binding Path="ConnectionProperties.LiteDisplayString"/>
            <Binding Path="File.FullName"/>
            <Binding Path="IsDirty"/>-->
        </MultiBinding>
    </Window.Title>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <ToolBarTray>
            <ToolBar Name="tbrFile" IsEnabled="{local:FormattedBinding Path=IsConnected, ValueIfTrue=False, ValueIfFalse=True}">
                <Button Name="tbbNewSplxFileStore" Margin="0,0,2,0" ToolTip="New Suplex File Store"
                    Click="tbbNewSplxFileStore_Click">
                    <Image Source="{local:FormattedBinding ElementName=tbrFile, Path=IsEnabled, ValueIfTrue='/SuplexAdmin;component/Resources/ToolBar/file/file_new_16x16.png', ValueIfFalse='/SuplexAdmin;component/Resources/ToolBar/file/file_new_16x16_grey.png'}" Width="16" Height="16"/>
                </Button>
                <cc:SplitButton x:Name="tbbOpenSplxFileStore" Style="{DynamicResource ToolBarSplitButtonStyle}" Tag="file_open"
                                Image="{local:FormattedBinding ElementName=tbrFile, Path=IsEnabled, ValueIfTrue='/SuplexAdmin;component/Resources/ToolBar/file/file_open_16x16.png', ValueIfFalse='/SuplexAdmin;component/Resources/ToolBar/file/file_open_16x16_grey.png'}"
                                ToolTip="Open Suplex File Store"
                                Click="tbbOpenSplxFileStore_Click">
                    <cc:SplitButton.DropDownContextMenu>
                        <ContextMenu ItemsSource="{Binding}" ItemTemplate="{StaticResource RecentFile}" MenuItem.Click="mnuRecentFile_Click" />
                    </cc:SplitButton.DropDownContextMenu>
                </cc:SplitButton>
                <cc:SplitButton x:Name="tbbSaveSplxFileStore" Style="{DynamicResource ToolBarSplitButtonStyle}" Tag="file_save"
                                ToolTip="Save Suplex File Store"
                                Click="tbbSaveSplxFileStore_Click">
                    <cc:SplitButton.Image>
                        <MultiBinding Converter="{StaticResource saveImageConverter}"
                                      ConverterParameter="/SuplexAdmin;component/Resources/ToolBar/file/,file_save_16x16.png,file_save_secure_16x16.png,file_save_16x16_grey.png,file_save_secure_16x16_grey.png">
                            <Binding ElementName="tbrFile" Path="IsEnabled"/>
                            <Binding Path="HasPublicPrivateKeyFile"/>
                        </MultiBinding>
                    </cc:SplitButton.Image>
                    <cc:SplitButton.DropDownContextMenu>
                        <ContextMenu>
                            <MenuItem Header="Save As" Tag="file_save_as" Click="tbbSaveSplxFileStore_Click">
                                <MenuItem.Icon>
                                    <Image>
                                        <Image.Source>
                                            <BitmapImage UriSource="/SuplexAdmin;component/Resources/ToolBar/file/file_save_as_16x16.png" />
                                        </Image.Source>
                                    </Image>
                                </MenuItem.Icon>
                            </MenuItem>
                            <MenuItem Header="Save Signed File" Tag="file_save_secure" Click="tbbSaveSplxFileStoreSecure_Click">
                                <MenuItem.Icon>
                                    <Image>
                                        <Image.Source>
                                            <BitmapImage UriSource="/SuplexAdmin;component/Resources/ToolBar/file/file_save_secure_16x16.png" />
                                        </Image.Source>
                                    </Image>
                                </MenuItem.Icon>
                            </MenuItem>
                        </ContextMenu>
                    </cc:SplitButton.DropDownContextMenu>
                </cc:SplitButton>
            </ToolBar>
            <ToolBar>
                <cc:SplitButton x:Name="tbbRemoteConnect" Style="{DynamicResource ToolBarSplitButtonStyle}"
                                Click="tbbRemoteConnect_Click" ToolTip="Connect to a remote Suplex service/database"
                                IsEnabled="{local:FormattedBinding ElementName=tbbRemoteDisconnect, Path=IsEnabled, ValueIfTrue=False, ValueIfFalse=True}"
                                Image="{local:FormattedBinding ElementName=tbbRemoteConnect, Path=IsEnabled, ValueIfTrue='/SuplexAdmin;component/Resources/Toolbar/service/service_connect_16x16.png', ValueIfFalse='/SuplexAdmin;component/Resources/Toolbar/service/service_connect_16x16_grey.png'}">
                    <cc:SplitButton.DropDownContextMenu>
                        <ContextMenu ItemsSource="{Binding}" ItemTemplate="{StaticResource RecentConnection}" MenuItem.Click="mnuRecentConnection_Click"/>
                    </cc:SplitButton.DropDownContextMenu>
                </cc:SplitButton>
                <Button Style="{DynamicResource ToolBar.ButtonStyleKey}" Name="tbbRemoteDisconnect"
                    Click="tbbRemoteDisconnect_Click" ToolTip="Disconnect"
                    IsEnabled="{local:FormattedBinding Path=IsConnected}">
                    <Image Source="{local:FormattedBinding ElementName=tbbRemoteDisconnect, Path=IsEnabled, ValueIfTrue='Resources\\Toolbar\\service\\service_disconnect_16x16.png', ValueIfFalse='Resources\\Toolbar\\service\\service_disconnect_16x16_grey.png'}" Height="16" Width="16"/>
                </Button>
                <Button Name="tbbRemoteRefresh" ToolTip="Refresh"
                        Click="tbbRemoteRefresh_Click"
                        IsEnabled="{local:FormattedBinding Path=IsConnected}">
                    <Image Source="{local:FormattedBinding ElementName=tbbRemoteRefresh, Path=IsEnabled, ValueIfTrue='Resources\\Toolbar\\service\\service_refresh_16x16.png', ValueIfFalse='Resources\\Toolbar\\service\\service_refresh_16x16_grey.png'}" Height="16" Width="16"/>
                </Button>
                <Button Name="tbbRemoteImport" ToolTip="Merge objects into a Suplex schema"
                        Click="tbbRemoteImport_Click"
                        IsEnabled="{local:FormattedBinding Path=IsConnected}">
                    <Image Source="{local:FormattedBinding ElementName=tbbRemoteImport, Path=IsEnabled, ValueIfTrue='Resources\\Toolbar\\service\\service_import_16x16.png', ValueIfFalse='Resources\\Toolbar\\service\\service_import_16x16_grey.png'}" Height="16" Width="16"/>
                </Button>
                <Button Name="tbbRemoteExport" ToolTip="Export objects from a Suplex schema"
                        Click="tbbRemoteExport_Click"
                        IsEnabled="{local:FormattedBinding Path=IsConnected}">
                    <Image Source="{local:FormattedBinding ElementName=tbbRemoteExport, Path=IsEnabled, ValueIfTrue='Resources\\Toolbar\\service\\service_export_16x16.png', ValueIfFalse='Resources\\Toolbar\\service\\service_export_16x16_grey.png'}" Height="16" Width="16"/>
                </Button>
            </ToolBar>
            <ToolBar>
                <RadioButton Name="tbbUie" Content="UI Elements" IsChecked="True" Style="{DynamicResource ToolBar.RadioButtonStyleKey}"/>
                <RadioButton Name="tbbSec" Content="Users/Groups" IsChecked="False" Style="{DynamicResource ToolBar.RadioButtonStyleKey}"/>
            </ToolBar>
        </ToolBarTray>

        <local:UIElementDlg x:Name="uieDlg" Grid.Row="1"
                            Visibility="{local:FormattedBinding Path=IsChecked, ElementName=tbbSec, ValueIfTrue=Collapsed, ValueIfFalse=Visible}" />
        <local:SecurityPrincipalDlg x:Name="spDlg" Grid.Row="1"
                                    Visibility="{local:FormattedBinding Path=IsChecked, ElementName=tbbSec, ValueIfTrue=Visible, ValueIfFalse=Collapsed}" />
    </Grid>
</Window>